package logic.ships.carrier;

import com.jme.math.Vector3f;

import ai.AIController;

public class CarrierController extends AIController {
	
	private static final long serialVersionUID = 1L;
	
	private Carrier carrier;
	private boolean arrived;
	
	public CarrierController(Carrier carrier) {
		super(carrier);
		this.carrier = carrier;
	}
	
	@Override
	public void delayedUpdate(float time) {
		if(carrier.arrived()) return;
		
		Vector3f moveLoc = carrier.getCurrentMoveLocation();
		
		if(moveLoc != null) {
			Vector3f currentPos = carrier.getLocalTranslation();
			
			if(currentPos.distance(moveLoc) < 5f) {
				carrier.getMoveForwardController().stop(true);
				arrived = true;
				carrier.getTeam().carrierArrived(carrier.getAsteroidField(), carrier);
			} else rotateTo(time / carrier.getMovableShipProperties().getTurnSpeed(), moveLoc);
		}
	}
	
	public boolean arrived() { return arrived; }
}